package com.ylr.user.framework.controller.api;

import com.ylr.user.framework.service.UserContactFlowService;
import com.ylr.base.common.annotation.Resubmit;
import com.ylr.base.common.tool.Result;
import com.ylr.user.common.vo.user.UserVo;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2023-03-30 16:44:48
 * className: UserContactFlowApiController 用户联系方式记录请求接口类
 * version: 1.0
 * description:
 */
@RestController
@RequestMapping("/api/user-contact-flow")
@AllArgsConstructor
public class UserContactFlowApiController {

    private static final Logger log = LoggerFactory.getLogger(UserContactFlowApiController.class);

    private final UserContactFlowService userContactFlowService;

    /**
     * 用户解绑手机号接口
     * <p>
     * 此接口会校验是否重复提交
     * @param userVo 参数对象
     */
    @Resubmit(spEL = "'unbindPhone'.concat(#userPo.id)", message = "解绑手机号")
    @PostMapping("/unbind/phone")
    public Result<Object> unbindPhone(@RequestBody UserVo userVo) {
        log.info("开始用户解绑手机号业务。mobile={}", userVo.getMobile());
        if (StringUtils.isBlank(userVo.getMobile())) {
            log.info("用户解绑手机号接口，请求参数错误");
            return Result.paramFail();
        }

        userContactFlowService.unbindPhone(userVo.getMobile());

        return Result.success();
    }

    /**
     * 用户解绑邮箱接口
     * <p>
     * 调用方：
     *  1、浏览器-后台管理页-个人中心调用
     * <p>
     * 此接口会校验是否重复提交
     * @param userVo 参数对象
     */
    @Resubmit(spEL = "'unbindEmail'.concat(#userPo.id)", message = "解绑邮箱")
    @PostMapping("/unbind/email")
    public Result<Object> unbindEmail(@RequestBody UserVo userVo) {
        log.info("开始用户解绑手机号业务。email={}", userVo.getEmail());
        if (StringUtils.isBlank(userVo.getEmail())) {
            log.info("用户解绑邮箱接口，请求参数错误");
            return Result.paramFail();
        }

        userContactFlowService.unbindEmail(userVo.getEmail());

        return Result.success();
    }

}
